<?php
/**
 * Filename:	GChartColorStyles.php
 * Author:		Manish Sinha
 * Date:		14/03/09
 * Details:		This file contains the class GChartColorStyles which
				contains data about the Fill Area, Solid Fill,
				Linear Gradient and Linear Stripes
 * Project:		GeeCharts
 */

class GChartColorStyles
{
	// bg is for BACKGROUND FILL
	// c is for CHART AREA FILL
	// a is for applying TRANSPARENCY to WHOLE CHART
	protected $fillType = array("BACK" => 'bg',
								"CHART_AREA" => 'c',
								"TRANS" => 'a');
	
	// GRADIENT or SOLID
	protected $gradList = array("LINEAR" => "lg", "SOLID" => "s");
	
	// Holds Solid fill Data
	protected $fillData = array();
	
	// Holds Linear Gradient Data
	protected $linGrad = array();
	
	// Holds Linear Strips Data
	protected $linStrips = array();
	
	public function AddSolidFill($fill,$color)
	{
		// Get the code for Chart Fill Type
		$type = $this->fillType[$fill];
		$fillData = array($type,"s",$color);
		
		// If this fill type has not been used then set it
		if(isset($this->fillData[$type]) == false)
			$this->fillData[$type] = $fillData;
		
		return $this;
	}
	
	public function GetChartFillString()
	{
		$tempArr = array();
		foreach($this->fillData as $fillrow)
		{
			$rowdata = $fillrow[0].",".$fillrow[1].",".$fillrow[2];
			array_push($tempArr,$rowdata);
		}
		
		return "chf=".implode("|",$tempArr);
	}
	
	public function AddLineGrad($fill,$gradType,$angle,$colorOffset)
	{
		// Get the code for Chart Fill Type
		$type = $this->fillType[$fill];
		if(is_array($colorOffset))
			$colorStr = implode(",",$colorOffset);
			
		$gradType = $this->gradList[$gradType];
		
		$fillData = array($type,$gradType,$angle,$colorStr);
		
		// If this fill type has not been used then set it
		if(isset($this->linGrad[$type]) == false)
			$this->linGrad[$type] = $fillData;
		
		return $this;
	}
	
	public function GetLineGradString()
	{
		$tempArr = array();
		foreach($this->linGrad as $gradrow)
		{
			$rowdata = $gradrow[0].",".$gradrow[1].",".$gradrow[2].",".$gradrow[3];
			array_push($tempArr,$rowdata);
		}
		
		return "chf=".implode("|",$tempArr);
	}
	
	public function AddLinearStrips($fill,$angle,$colorWidth)
	{
		// Get the code for Chart Fill Type
		$type = $this->fillType[$fill];
		if(is_array($colorWidth))
			$colorStr = implode(",",$colorWidth);
		
		$fillData = array($type,"ls",$angle,$colorStr);
		
		// If this fill type has not been used then set it
		if(isset($this->linStrips[$type]) == false)
			$this->linStrips[$type] = $fillData;
		
		return $this;
	}
	
	public function GetLinearStripsString()
	{
		$tempArr = array();
		foreach($this->linStrips as $gradrow)
		{
			$rowdata = $gradrow[0].",".$gradrow[1].",".$gradrow[2].",".$gradrow[3];
			array_push($tempArr,$rowdata);
		}
		
		return "chf=".implode("|",$tempArr);
	}
}
